package xyz.scootaloo.oj.offer

import xyz.scootaloo.oj.ds.TreeNode

/**
 * @author flutterdash@qq.com
 * @since 2021/4/12 16:35
 */
class P55I {

    fun maxDepth(root: TreeNode?): Int {
        if (root == null) return 0
        val res = IntArray(1)
        dfs(root, 1, res)
        return res[0]
    }

    private fun dfs(root: TreeNode, currentDepth: Int, max: IntArray) {
        if (currentDepth > max[0]) {
            max[0] = currentDepth
        }
        if (root.left != null) {
            dfs(root.left, currentDepth + 1, max)
        }
        if (root.right != null) {
            dfs(root.right, currentDepth + 1, max)
        }
    }

}
